<template>
  <view >
    <button @click="upload" class="but">识别身份证</button>
    <div class="card_info">
        <view class="li">姓名：{{caidData.LD_NAME || ''}}</view>
        <view class="li">性别：{{caidData.SEX || ''}}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;民族：{{caidData.LD_MZ || ''}}</view>
        <view class="li">出生：{{caidData.LD_BIRTHDAY || ''}}</view>
        <view class="li">住址：{{caidData.LD_ADDRESS || ''}}</view>
        <view class="li">身份证号码：{{caidData.LD_ID || ''}}</view>
        <view class="user_pic">
            <image :src="$host+caidData.LD_IMG" v-if="caidData.LD_IMG" @click="uploadimg"></image>
            <image src="/static/img/default.png" v-else  @click="uploadimg"></image>
            <text>点击拍照</text>
        </view>
    </div>
    <view class="uni-list">
        <view class="uni-list-cell">
            <view class="uni-list-cell-left">
                <text>与户主关系</text>
            </view>
            <view class="uni-list-cell-db">
                <picker @change="bindsecurityChange" :value="securityindex" :range="securityType">
                    <text class="uni-input">{{securityType[securityindex]}}</text>
                    <image src="/static/img/right.png" class="right_img"></image>
                </picker>
            </view>
        </view>
        <view class="uni-list-cell">
            <view class="uni-list-cell-left">
                <text>救助类别</text>
            </view>
            <view class="uni-list-cell-db">
                <picker @change="bindhouseholdChange" :value="householdindex" :range="householdType" range-key="dict_sub3" :disabled="securityType[securityindex]=='户主'">
                    <text class="uni-input">{{householdType[householdindex].dict_sub3}}</text>
                    <image src="/static/img/right.png" class="right_img"></image>
                </picker>
            </view>
        </view>
        <view class="item">
            <view class="imglist" v-if="caidData.LD_CLASS2IMG.length">
                <div class="relative" v-for="(item, index) in caidData.LD_CLASS2IMG" :key="item">
                    <image src="/static/img/removeImg.jpg" @click.stop="removeImg(caidData.LD_CLASS2IMG,index)" class="removeImg"></image>
                    <image :src="$host+item" class="user_pic" @click="previewImage(caidData.LD_CLASS2IMG, index)"></image>
                </div>
                <image src="/static/img/upload.png" class="user_pic" @click="uploadpictures(0)"></image>
            </view>
            <image src="/static/img/upload.png" v-if="!caidData.LD_CLASS2IMG.length" @click="uploadpictures(0)"></image>
            <text class="explain" v-if="!caidData.LD_CLASS2IMG.length">提供户籍证明</text>
        </view>
    </view>
    <view class="uni-list">
        <view class="uni-list-cell">
            <view class="uni-list-cell-left">
                <switch @change="switchChange" :checked="disabilityDisabled" data-type="残疾"/><text>是否残疾</text>
            </view>
            <view class="uni-list-cell-db">
                <picker :value="disabilityindex" :range="disabilityList" mode="multiSelector" @change="bindMultiPickerChange" data-type="残疾" :disabled="!disabilityDisabled" v-if="disabilityDisabled">
                    <text class="uni-input">{{disabilityList[0][disabilityindex[0]]}} - {{disabilityList[1][disabilityindex[1]]}}</text>
                    <image src="/static/img/right.png" class="right_img"></image>
                </picker>
            </view>
        </view>
        <view class="item" v-if="disabilityDisabled">
            <view class="imglist" v-if="FACTORS_disability.IMG.length">
                <div class="relative" v-for="(item, index) in FACTORS_disability.IMG" :key="item">
                    <image src="/static/img/removeImg.jpg" @click.stop="removeImg(FACTORS_disability.IMG,index)" class="removeImg"></image>
                    <image :src="$host+item" @click="previewImage(FACTORS_disability.IMG, index)" class="user_pic" ></image>
                </div>
                <image src="/static/img/upload.png" class="user_pic" @click="uploadpictures(3)"></image>
            </view>
            <image src="/static/img/upload.png" v-if="!FACTORS_disability.IMG.length" @click="uploadpictures(3)"></image>
            <text class="explain" v-if="!FACTORS_disability.IMG.length">提供残疾证明</text>
        </view>
    </view>
    <view class="uni-list">
        <view class="uni-list-cell">
            <view class="uni-list-cell-left">
                <switch @change="switchChange" :checked="illnessDisabled" data-type="患病"/><text>是否患病</text>
            </view>
            <view class="uni-list-cell-db">
                <picker :value="illnessindex" :range="illnessList" @columnchange="bindMultiPickerColumnChange" mode="multiSelector" @change="bindMultiPickerChange" data-type="患病" :disabled="!illnessDisabled" v-if="illnessDisabled">
                    <text class="uni-input">{{illnessList[0][illnessindex[0]]}} - {{illnessList[1][illnessindex[1]]}}</text>
                    <image src="/static/img/right.png" class="right_img"></image>
                </picker>
            </view>
        </view>
        <view class="item" v-if="illnessDisabled">
            <view class="imglist" v-if="FACTORS_illness.IMG.length">
                <div class="relative" v-for="(item, index) in FACTORS_illness.IMG" :key="item">
                    <image src="/static/img/removeImg.jpg" @click.stop="removeImg(FACTORS_illness.IMG,index)" class="removeImg"></image>
                    <image :src="$host+item" class="user_pic" @click="previewImage(FACTORS_illness.IMG, index)"></image>
                </div>
                <image src="/static/img/upload.png" class="user_pic" @click="uploadpictures(4)"></image>
            </view>
            <image src="/static/img/upload.png" v-if="!FACTORS_illness.IMG.length" @click="uploadpictures(4)"></image>
            <text class="explain" v-if="!FACTORS_illness.IMG.length">
                <text>慢性疾病：提供当年之内医疗症断书</text>
                <text>重大疾病：提供三年之内医疗症断书</text>
            </text>
        </view>
    </view>
    <view class="uni-list">
        <view class="uni-list-cell">
            <view class="uni-list-cell-left">
                <switch @change="switchChange" :checked="inabilityDisabled" data-type="失能"/><text>是否失能</text>
            </view>
            <view class="uni-list-cell-db" >
                <picker @change="bindMultiPickerChange" data-type="失能" :value="inabilityindex" :range="inabilityList" disabled v-if="inabilityDisabled">
                    <text class="uni-input">{{inabilityList[inabilityindex]}}</text>
                    <image src="/static/img/right.png" class="right_img"></image>
                </picker>
            </view>
        </view>
        <view class="item" v-if="inabilityDisabled">
            <checkbox-group @change="checkboxChange">
                <label class="uni-list-cell-pd" v-for="item in inabilityitems" :key="item.value">
                    <view><checkbox :value="item.value" :checked="item.checked" />{{item.value}}</view>
                </label>
            </checkbox-group>
        </view>
    </view>
    <view class="uni-list">
        <view class="uni-list-cell">
            <view class="uni-list-cell-left">
                <switch @change="switchChange" :checked="studentDisabled" data-type="教育"/><text>是否在读学生</text>
            </view>
            <view class="uni-list-cell-db" >
                <picker @change="bindMultiPickerChange" data-type="教育" :value="studentindex" :range="studentList" :disabled="!studentDisabled" v-if="studentDisabled">
                    <text class="uni-input">{{studentList[studentindex]}}</text>
                    <image src="/static/img/right.png" class="right_img"></image>
                </picker>
            </view>
        </view>
        <view class="item" v-if="studentDisabled">
            <view class="imglist" v-if="FACTORS_studentList.IMG.length">
                <div class="relative" v-for="(item, index) in FACTORS_studentList.IMG" :key="item">
                    <image src="/static/img/removeImg.jpg" @click.stop="removeImg(FACTORS_studentList.IMG,index)" class="removeImg"></image>
                    <image :src="$host+item" @click="previewImage(FACTORS_studentList.IMG, index)" class="user_pic"></image>
                </div>
                <image src="/static/img/upload.png" class="user_pic" @click="uploadpictures(5)"></image>
            </view>
            <image src="/static/img/upload.png" v-if="!FACTORS_studentList.IMG.length" @click="uploadpictures(5)"></image>
            <text class="explain" v-if="!FACTORS_studentList.IMG.length">提供学生证明</text>
        </view>
    </view>
    <view class="uni-list">
        <view class="uni-list-cell">
            <view class="uni-list-cell-left">
                <switch @change="switchChange" :checked="workDisabled" data-type="工作"/><text>是否固定工作</text>
            </view>
            <view class="uni-list-cell-db">
                <input class="uni-input" placeholder="请输入月工资" :value="caidData.LD_WAGE" @input="workChange" type="number" :disabled="!workDisabled" v-if="workDisabled"/>
            </view>
        </view>
        <view class="item" v-if="workDisabled">
            <view class="imglist" v-if="caidData.LD_WAGEIMG.length">
                <div class="relative" v-for="(item,index) in caidData.LD_WAGEIMG" :key="item">
                    <image src="/static/img/removeImg.jpg" @click.stop="removeImg(caidData.LD_WAGEIMG,index)" class="removeImg"></image>
                    <image :src="$host+item" @click="previewImage(caidData.LD_WAGEIMG, index)" class="user_pic"></image>
                </div>
                <image src="/static/img/upload.png" class="user_pic" @click="uploadpictures(1)"></image>
            </view>
            <image src="/static/img/upload.png" v-if="!caidData.LD_WAGEIMG.length" @click="uploadpictures(1)"></image>
            <text class="explain" v-if="!caidData.LD_WAGEIMG.length">提供近三个月工资证明</text>
        </view>
    </view>
    <view class="uni-list">
        <view class="uni-list-cell">
            <view class="uni-list-cell-left">
                <switch @change="switchChange" :checked="retireDisabled" data-type="退休"/><text>是否离退休</text>
            </view>
            <view class="uni-list-cell-db">
                <input class="uni-input" placeholder="请输入离退休金" :value="caidData.LD_PENS" @input="retireChange" type="number" :disabled="!retireDisabled" v-if="retireDisabled"/>
            </view>
        </view>
        <view class="item" v-if="retireDisabled">
            <view class="imglist" v-if="caidData.LD_PENSIMG.length">
                <div class="relative" v-for="(item,index) in caidData.LD_PENSIMG" :key="item">
                    <image src="/static/img/removeImg.jpg" @click.stop="removeImg(caidData.LD_PENSIMG,index)" class="removeImg"></image>
                    <image :src="$host+item" @click="previewImage(caidData.LD_PENSIMG, index)" class="user_pic"></image>
                </div>
                <image src="/static/img/upload.png" class="user_pic" @click="uploadpictures(2)"></image>
            </view>
            <image src="/static/img/upload.png" v-if="!caidData.LD_PENSIMG.length" @click="uploadpictures(2)"></image>
            <text class="explain" v-if="!caidData.LD_PENSIMG.length">提供近三个月退休金发放证明</text>
        </view>
    </view>
    <button @click="goEditallowances" class="but">确定</button>
  </view>
</template>

<script>
import { guid } from '@/utils/tool.js'
  export default {
    data() {
      return {
        MIN_WAGE_LINE:0,
        index:0,
        isAdd: 0, // 0添加，1编辑
        isWindows: false,
        securityType: ['户主','妻子','丈夫','父亲','母亲','儿子','女儿','孙子','孙女','其它'],
        householdType: [],
        securityindex: 0,
        householdindex: 0,
        disabilityList: [[],[]],  // 残疾
        illnessList: [[],[]],  // 患病
        inabilityList: [],  // 失能
        studentList: [],  // 在读学生
        disabilityindex: [0, 0],
        illnessindex: [0, 0],
        studentindex: 0,
        inabilityindex: 1,
        disabilityDisabled: false,
        illnessDisabled: false,
        inabilityDisabled: false,
        studentDisabled: false,
        workDisabled: false,
        retireDisabled: false,
        caidData: {
            "LM_GUID":"",//户号
            "LD_ID":"",//身份证号
            "LD_NAME":"",//姓名
            "SEX":"",//性别
            "LD_BIRTHDAY":"",//生日 yyyy-MM-dd
            "LD_ADDRESS":"",//地址
            "LD_IMG":"",//头像
            "LD_CLASS2":"",//救助类别
            "LD_CLASS2IMG":[],//户籍证明材料，多图用逗号,隔开
            "LD_REL":"",//与户主关系，必须要有一个成员是户主
            "LD_WAGE":0,//固定工资收入
            "LD_WAGEIMG":[],//工资收入证明图片，多图用逗号,隔开(存服务器返回的相对路径)
            "LD_PENS":0,//离退休金
            "LD_PENSIMG":[],//离退休金证明图片，多图用逗号,隔开(存服务器返回的相对路径)
            "LD_ROLE":"",//成员角色：保障人员、赡养人员
            "FACTORS":[]
        },
        userimg: '',
        $host: this.$host,
        navList: [],
        inabilityitems: [
            {value: '不能自主吃饭', checked: false},
            {value: '不能自主穿衣', checked: false},
            {value: '不能自主上下床', checked: false},
            {value: '不能自主如厕', checked: false},
            {value: '不能自主行走', checked: false},
            {value: '不能自主洗浴', checked: false}
        ],
        inabilityitemslist:[],
        FACTORS_disability: {
            IMG: []
        },
        FACTORS_illness: {
            IMG: []
        },
        FACTORS_inability: {},
        FACTORS_studentList: {
            IMG: []
        },
      }
    },
    onLoad(options) {
        this.globalGetData('系统参数', 'dict_sub3', '救助类别')
        this.globalGetData('劳动力系数', 'dict_sub1,dict_sub2,dict_sub3', '劳动力类型')
        let that = this;
        uni.getSystemInfo({
            success: function (res) {
                if (res.platform == 'windows') {
                    that.isWindows = true
                }
            }
        });
        uni.getStorage({
            key: 'MIN_WAGE_LINE',
            success: function (res) {
                that.MIN_WAGE_LINE = res.data
            }
        });
        this.isAdd = Number(options.isAdd);
        if (!Number(options.isAdd)) {
            this.caidData.LM_GUID = options.LM_GUID
            this.caidData.LD_ROLE = options.LD_ROLE
        } else {
            uni.showLoading({
                title: '加载中'
            });
            this.index = options.index;
            this.caidData = Object.assign(this.caidData ,JSON.parse(decodeURIComponent(options.data)))
            console.log(this.caidData)
        }
        // 判断是否有重复户主
        let pages = getCurrentPages();
        let currPage = pages[pages.length - 1];   //当前页面
        let prevPage = pages[pages.length - 2];  //上一个页面
        prevPage.$vm.caidData.DT_DETAIL.forEach(item => {
            if (item.LD_REL == '户主' && that.caidData.LD_REL != '户主') {
                that.securityType.splice(0,1)
            }
        });
    },
    methods: {
        // 编辑回显
        edidEcho () {
            this.securityindex = this.securityType.indexOf(this.caidData.LD_REL)
            this.householdType.forEach((item,index) => {
                if (item.dict_sub3 == this.caidData.LD_CLASS2) {
                    this.householdindex = index
                }
            });
            this.caidData.FACTORS.forEach(item => {
                if (item.SUB1 == '残疾') {
                    this.FACTORS_disability = item
                    this.disabilityDisabled = true
                    this.disabilityindex[0] = this.disabilityList[0].indexOf(item.SUB2)
                    this.disabilityindex[1] = this.disabilityList[1].indexOf(item.ITEMNAME)
                }
                if (item.SUB1 == '患病') {
                    this.FACTORS_illness = item
                    this.illnessDisabled = true
                    this.illnessindex[0] = this.illnessList[0].indexOf(item.SUB2)
                    this.illnessindex[1] = this.illnessList[1].indexOf(item.ITEMNAME)
                }
                if (item.SUB1 == '失能') {
                    this.FACTORS_inability = item
                    this.inabilityDisabled = true
                    this.inabilityindex = this.inabilityList.indexOf(item.SUB2)
                    this.FACTORS_inability.ITEMNAME = this.FACTORS_inability.ITEMNAME.split(",")
                    this.FACTORS_inability.ITEMNAME.forEach((item,index) => {
                        this.inabilityitems.forEach(element => {
                            if (item == element.value) {
                                this.inabilityitems[index].checked = true
                            }
                        })
                    });
                }
                if (item.SUB1 == '在读学生') {
                    this.FACTORS_studentList = item
                    this.studentDisabled = true
                    this.studentindex = this.studentList.indexOf(item.SUB2)
                }
            });
            if (this.caidData.LD_WAGE) {
                this.workDisabled = true
            }
            if (this.caidData.LD_PENS) {
                this.retireDisabled = true
            }
        },
        // 与户主关系
        bindsecurityChange(e) {
            this.securityindex = e.target.value
            this.caidData.LD_REL = this.securityType[this.securityindex]
        },
        // 救助类别
        bindhouseholdChange(e) {
            this.householdindex = e.target.value
            this.caidData.LD_CLASS2 = this.householdType[this.householdindex].dict_sub3
        },
        // 是否关闭
        switchChange (e) {
            switch (e.currentTarget.dataset.type) {
                case '残疾':
                    this.disabilityDisabled = e.detail.value
                    break;
                case '患病':
                    this.illnessDisabled = e.detail.value
                    break;
                case '教育':
                    this.studentDisabled = e.detail.value
                    break;
                case '失能':
                    this.inabilityDisabled = e.detail.value
                    break;
                case '工作':
                    this.workDisabled = e.detail.value
                    break;
                case '退休':
                    this.retireDisabled = e.detail.value
                    break;
            }
        },
        // 下拉选择
        bindMultiPickerChange(e) {
            switch (e.currentTarget.dataset.type) {
                case '残疾':
                    this.disabilityindex = e.detail.value
                    break;
                case '患病':
                    this.illnessindex = e.detail.value
                    break;
                case '教育':
                    this.studentindex = e.detail.value
                    break;
                // case '失能':
                //     this.inabilityindex = e.detail.value
                //     break;
            }
        },
        // 下拉二级选择
        bindMultiPickerColumnChange(e) {
            if (e.detail.column) {
                return false
            }
            let community = []
            this.navList.forEach(item => {
                if (this.illnessList[0][e.detail.value] == item.dict_sub2) {
                    community.push(item.dict_sub3)
                }
            });
            this.illnessList[1] = community
            this.illnessList.push()
        },
        // 失能选择
        checkboxChange: function (e) {
            let length = e.detail.value.length;
            this.FACTORS_inability.ITEMNAME = e.detail.value
            if (length>=4) {
                this.inabilityindex = 0
            } else {
                this.inabilityindex = 1
            }
        },
        workChange (e) {
            this.caidData.LD_WAGE = e.detail.value
        },
        retireChange (e) {
            this.caidData.LD_PENS = e.detail.value
        },
        // 合数据，返回上一页
        goEditallowances () {
            if (!this.caidData.LD_ID) {
                uni.showToast({title: '请录入身份证',icon: 'none'});
                return false
            }
            if (!this.caidData.LD_IMG && this.caidData.LD_ROLE == '保障人员') {
                uni.showToast({title: '请上传身份证头像',icon: 'none'});
                return false
            }
            if (!this.caidData.LD_CLASS2IMG.length) {
                uni.showToast({title: '请上传户籍证明材料',icon: 'none'});
                return false
            }
            this.caidData.FACTORS = [];
            this.caidData.LD_CLASS2 = this.householdType[this.householdindex].dict_sub3
            this.caidData.LD_REL = this.securityType[this.securityindex]
            // 残疾
            if (this.disabilityDisabled) {
                if (!this.FACTORS_disability.IMG.length) {
                    uni.showToast({title: '请上传残疾证明材料',icon: 'none'});
                    return false
                }
                this.FACTORS_disability.LM_GUID = this.caidData.LM_GUID
                this.FACTORS_disability.LD_ID = this.caidData.LD_ID
                this.FACTORS_disability.SUB1 = '残疾'
                this.FACTORS_disability.SUB2 = this.disabilityList[0][this.disabilityindex[0]]
                this.FACTORS_disability.ITEMNAME = this.disabilityList[1][this.disabilityindex[1]]
                this.caidData.FACTORS.push(this.FACTORS_disability)
            }
            // 患病
            if (this.illnessDisabled) {
                if (!this.FACTORS_illness.IMG.length) {
                    uni.showToast({title: '请上传患病证明材料',icon: 'none'});
                    return false
                }
                this.FACTORS_illness.LM_GUID = this.caidData.LM_GUID
                this.FACTORS_illness.LD_ID = this.caidData.LD_ID
                this.FACTORS_illness.SUB1 = '患病'
                this.FACTORS_illness.SUB2 = this.illnessList[0][this.illnessindex[0]]
                this.FACTORS_illness.ITEMNAME = this.illnessList[1][this.illnessindex[1]]
                this.caidData.FACTORS.push(this.FACTORS_illness)
            }
            // 失能
            if (this.inabilityDisabled) {
                if (!this.FACTORS_inability.ITEMNAME) {
                    uni.showToast({title: '请至少选择一个失能项',icon: 'none'});
                    return false
                }
                this.FACTORS_inability.LM_GUID = this.caidData.LM_GUID
                this.FACTORS_inability.LD_ID = this.caidData.LD_ID
                this.FACTORS_inability.SUB1 = '失能'
                this.FACTORS_inability.SUB2 = this.inabilityList[this.inabilityindex]
                this.FACTORS_inability.ITEMNAME = this.FACTORS_inability.ITEMNAME.join(",")
                this.caidData.FACTORS.push(this.FACTORS_inability)
            }
            // 在读学生
            if (this.studentDisabled) {
                if (!this.FACTORS_studentList.IMG.length) {
                    uni.showToast({title: '请上传学生证明材料',icon: 'none'});
                    return false
                }
                this.FACTORS_studentList.LM_GUID = this.caidData.LM_GUID
                this.FACTORS_studentList.LD_ID = this.caidData.LD_ID
                this.FACTORS_studentList.SUB1 = '在读学生'
                this.FACTORS_studentList.SUB2 = this.studentList[this.studentindex]
                this.FACTORS_studentList.ITEMNAME = ''
                this.caidData.FACTORS.push(this.FACTORS_studentList)
            }
            // 工作
            if (this.workDisabled) {
                if (!this.caidData.LD_WAGEIMG.length) {
                    uni.showToast({title: '请上传工作证明材料',icon: 'none'});
                    return false
                }
                this.caidData.LD_WAGE = Number(this.caidData.LD_WAGE)
                if (this.caidData.LD_WAGE == 0 || this.caidData.LD_WAGE < this.MIN_WAGE_LINE) {
                    uni.showToast({title: '工资不能为0且不能小于'+this.MIN_WAGE_LINE+"元",icon: 'none'});
                    return false
                }
            }
            // 退休金
            if (this.retireDisabled) {
                if (!this.caidData.LD_PENSIMG.length) {
                    uni.showToast({title: '请上传退休金证明材料',icon: 'none'});
                    return false
                }
                this.caidData.LD_PENS = Number(this.caidData.LD_PENS)
                if (this.caidData.LD_PENS == 0 || this.caidData.LD_PENS < this.MIN_WAGE_LINE) {
                    uni.showToast({title: '退休金不能为0且不能小于'+this.MIN_WAGE_LINE+"元",icon: 'none'});
                    return false
                }
            }
            let that = this;
            let pages = getCurrentPages();
            let currPage = pages[pages.length - 1];   //当前页面
            let prevPage = pages[pages.length - 2];  //上一个页面
            if (this.isAdd) {
                prevPage.$vm.caidData.DT_DETAIL[this.index] = that.caidData
            } else {
                // 判断是否重复人
                let ishave = false;
                prevPage.$vm.caidData.DT_DETAIL.forEach(item => {
                    if (item.LD_ID == that.caidData.LD_ID) {
                        ishave = true
                    }
                });
                if (!ishave) {
                    prevPage.$vm.caidData.DT_DETAIL.push(that.caidData);
                } else {
                    uni.showModal({
                        title: '提示',
                        showCancel: false,
                        content: '已有此人员，请更改'
                    });
                    return false
                }
            }
            uni.navigateBack({delta: 1})
        },
        // 识别身份证
        upload() {
            if (this.isWindows) {
                uni.showModal({
                    title: '提示',
                    showCancel: false,
                    content: '不支持电脑上传图片，请用手机操作'
                });
                return false
            }
            let that = this
            uni.chooseImage({
                count: 1,
                sizeType: ['compressed'],
                sourceType: ['camera'],
                success: function (self) {
                    that.$http.upload('Getidcard', {
						filePath: self.tempFilePaths[0], 
						name: encodeURI('filePath'),
						formData:{
						    "LM_GUID":that.caidData.LM_GUID
						}
                    }).then(res => {
                        if (JSON.parse(res).error_code === 0) {
                            let data = JSON.parse(res).data.IDCARD
                            that.caidData.LD_ID = data.ID
                            that.caidData.LD_NAME = data.NAME
                            that.caidData.SEX = data.SEX
                            that.caidData.LD_BIRTHDAY = data.BIRTHDAY
                            that.caidData.LD_ADDRESS = data.ADDRESS
                            that.caidData.LD_MZ = data.MZ
                            that.caidData.LD_IMG = data.photo
                        } else {
                            uni.showToast({
                                title: '识别失败',
                                duration: 2000,
                                icon: 'none'
                            });
                        }
                    })
                }
            })
        },
        // 录入身份证照片
        uploadimg() {
            if (this.isWindows) {
                uni.showModal({
                    title: '提示',
                    showCancel: false,
                    content: '不支持电脑上传图片，请用手机操作'
                });
                return false
            }
            let that = this
            uni.chooseImage({
                count: 1,
                sizeType: ['compressed'],
                sourceType: ['camera'],
                success: function (self) {
                    that.$http.upload('uploadLDIMG', {filePath: self.tempFilePaths[0], name: encodeURI('filePath'),formData:{
                        "LM_GUID":that.caidData.LM_GUID,
                        "LD_ID":that.caidData.ID,
                        "ckface":"true"
                    }
                    }).then(res => {
                        if (JSON.parse(res).error_code == 0) {
                            let QC = JSON.parse(res).data.QC; 
                            if (QC.score == 1) {
                                that.caidData.LD_IMG = JSON.parse(res).data.RPATH
                            } else {
                                uni.showModal({
                                    title: '提示',
                                    showCancel: false,
                                    content: QC.message
                                });
                            }
                        } else {
                            uni.showModal({
                                title: '提示',
                                showCancel: false,
                                content: JSON.parse(res).error_msg
                            });
                        }
                    })
                }
            })
        },
        // 录入证明图片
        uploadpictures(type) {
            if (this.isWindows) {
                uni.showModal({
                    title: '提示',
                    showCancel: false,
                    content: '不支持电脑上传图片，请用手机操作'
                });
                return false
            }
            let that = this
            uni.chooseImage({
                count: 1,
                sizeType: ['compressed'],
                sourceType: ['camera', 'album'],
                success: function (self) {
                    that.$http.upload('uploadLDIMG', {filePath: self.tempFilePaths[0], name: encodeURI('filePath'),formData:{
                        "LM_GUID":that.caidData.LM_GUID,
                        "LD_ID":that.caidData.ID,
                        "ckface":false
                    }
                    }).then(res => {
                        let imginfo = JSON.parse(res).data
                        switch (type) {
                            case 0: // 户籍证明材料，多图用逗号
                                that.caidData.LD_CLASS2IMG.push(imginfo.RPATH)
                                break;
                            case 1: // 工资收入证明图片
                                that.caidData.LD_WAGEIMG.push(imginfo.RPATH)
                                break;
                            case 2: // 离退休金证明
                                that.caidData.LD_PENSIMG.push(imginfo.RPATH)
                                break;
                            case 3: // 残疾证明
                                that.FACTORS_disability.IMG.push(imginfo.RPATH)
                                break;
                            case 4: // 患病证明
                                that.FACTORS_illness.IMG.push(imginfo.RPATH)
                                break;
                            case 5: // 在读学生证明
                                that.FACTORS_studentList.IMG.push(imginfo.RPATH)
                                break;
                        }
                    })
                }
            })
        },
        // 获取数据字典
        globalGetData(dict_sub, showField, type) {
            let that = this;
            this.$http.get('dicts', {params: {dict_sub: dict_sub, dict_sub1: '',dict_sub2: '',showField: showField}}).then(res => {
                switch (type) {
                    case '救助类别':
                        this.householdType = res.data
                        break;
                    case '劳动力类型':
                        res.data.forEach(item => {
                            if (item.dict_sub1 == '残疾') {
                                this.disabilityList[0].push(item.dict_sub2)
                                if (item.dict_sub2 === this.disabilityList[0][0]) {
                                    this.disabilityList[1].push(item.dict_sub3)
                                }
                                this.disabilityList[0] = Array.from(new Set(this.disabilityList[0]))
                                this.disabilityList[1] = Array.from(new Set(this.disabilityList[1]))
                            }
                            if (item.dict_sub1 == '患病') {
                                this.navList.push(item)
                                this.illnessList[0].push(item.dict_sub2)
                                if (item.dict_sub2 === this.illnessList[0][0]) {
                                    this.illnessList[1].push(item.dict_sub3)
                                }
                                this.illnessList[0] = Array.from(new Set(this.illnessList[0]))
                                this.illnessList[1] = Array.from(new Set(this.illnessList[1]))
                            }
                            if (item.dict_sub1 == '教育') {
                                this.studentList.push(item.dict_sub2)
                            }
                            if (item.dict_sub1 == '失能') {
                                this.inabilityList.push(item.dict_sub2)
                            }
                        });
                        if (that.isAdd) {
                            uni.hideLoading()
                            that.edidEcho()
                        }
                        break;
                }
            })
        },
        // 预览图片
        previewImage (tempFilePaths, index) {
            let imglist = []
            tempFilePaths.forEach(item => {
                imglist.push(this.$host + item)
            });
            uni.previewImage({
                current: index,
                urls: imglist
            });
        },
        // 删除图片
        removeImg (tempFilePaths, index) {
            uni.showModal({
                title: '删除提示',
                content: '是否确定删除该图片？',
                success: function (res) {
                    if (res.confirm) {
                        tempFilePaths.splice(index,1)
                    }
                }
            });
        }
    }
  }
</script>

<style lang="scss" scoped>
.but{
    background-color: #1EC88B;
    border: none;
    height: 94upx;
    line-height: 94upx;
    text-align: center;
    border-radius: 10upx;
    color: #fff;
    margin:20upx;
    font-size: 36upx;
}
.card_info{
    border-top: 1px solid #bbb;
    border-bottom: 1px solid #bbb;
    font-size: 28upx;
    color: #101010;
    padding: 28upx;
    position: relative;
    .li{
        line-height: 60upx;
    }
    .user_pic{
        position: absolute;
        right: 28upx;
        font-size: 24rpx;
        text-align: center;
        top: 28upx;
        image{
            display: block;
            margin-bottom: 10rpx;
            width: 150upx;
            height: 160upx;
        }
    }
}
.uni-list-cell{
    margin: 12upx 0;
    display: flex;
    height: 100upx;
    align-items: center;
    font-size: 32upx;
    color: #6D6E71;
    // padding: 0 30upx;
    justify-content: space-between;
    .uni-list-cell-left{
        .down_img{
            margin-right: 20upx;
            width: 44upx;
            height: 44upx;
            vertical-align: middle;
        }
        text{
            vertical-align: middle;
        }
    }
    .uni-list-cell-db{
        width: 50%;
        font-size: 24upx;
        text-align: right;
    }
    .uni-input{
       vertical-align: middle; 
    }
    .right_img{
        width: 50upx;
        height: 50upx;
        vertical-align: middle;
    }
}
.uni-list{
    padding:0 30upx;
    .item{
        color: #6D6E71;
        padding: 30upx;
        font-size: 24upx;
        box-sizing: border-box;
        border-top: solid 1px #E5E5E5;
        border-bottom: solid 1px #E5E5E5;
        display: block;
        .uni-list-cell-pd{
            display: inline-block;
            width: 50%;
            font-size: 32upx;
            margin: 10upx 0;
        }
        .imglist{
            .user_pic{
                width: 150upx;
                height: 150upx;
                margin:0rpx 20rpx 20rpx 20rpx;
                padding: 0;
            }
            .relative{
                position: relative;
                display: inline-block;
                .removeImg{
                    width: 36upx;
                    height: 36upx;
                    position: absolute;
                    right: 6upx;
                    top: -14upx;
                    border: 0;
                    margin: 0;
                    padding: 0;
                    z-index: 2;
                }
            }
        }
        image{
            width: 80upx;
            height: 90upx;
            padding: 20upx;
            display: inline-block;
            border: solid 2upx #E5E5E5;
            margin: 0 80upx 0 20upx;
            vertical-align:middle;
        }
        .explain{
            display: inline-block;
            vertical-align:middle;
            text{
                line-height: 50upx;
                display: block;
            }
        }
    }
}
</style>
